apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: bitbucket-demo
  title: Test Bitbucket RepoUrlPicker template
  description: scaffolder v1beta3 template demo publishing to bitbucket
spec:
  owner: backstage/techdocs-core
  type: service

  parameters:
    - title: Choose a location
      required:
        - repoUrl
      properties:
        repoUrl:
          title: Repository Location
          type: string
          ui:field: RepoUrlPicker
          ui:options:
            allowedHosts:
              - bitbucket.org
            # The rest of these options are optional.
            # You can read more at: https://backstage.io/docs/reference/plugin-scaffolder.repourlpickerfieldextension
            # allowedOwners:
            #   - WORKSPACE1
            #   - WORKSPACE2
            # allowedProjects:
            #   - PROJECT1
            #   - PROJECT2
            # allowedRepos:
            #   - REPO1
            #   - REPO2
    - title: Fill in some steps
      required:
        - name
        - owner
      properties:
        name:
          title: Name
          type: string
          description: Unique name of the component
          ui:autofocus: true
          ui:options:
            rows: 5
        owner:
          title: Owner
          type: string
          description: Owner of the component
          ui:field: OwnerPicker
          ui:options:
            catalogFilter:
              kind: Group

  steps:
    - id: fetch-base
      name: Fetch Base
      action: fetch:template
      input:
        url: ./template
        values:
          name: ${{ parameters.name }}
          owner: ${{ parameters.owner }}
    - id: fetch-docs
      name: Fetch Docs
      action: fetch:plain
      input:
        targetPath: ./community
        url: https://github.com/backstage/community/tree/main/backstage-community-sessions
    - id: publish
      name: Publish
      action: publish:bitbucket
      input:
        description: This is ${{ parameters.name }}
        repoUrl: ${{ parameters.repoUrl }}

    - id: register
      name: Register
      action: catalog:register
      input:
        repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }}
        catalogInfoPath: '/catalog-info.yaml'

  output:
    links:
      - title: Repository
        url: ${{ steps['publish'].output.remoteUrl }}
      - title: Open in catalog
        icon: catalog
        entityRef: ${{ steps['register'].output.entityRef }}
